//游戏相关全局变量和定义

global.gSkillFullLevel = 10;
global.gDefaultRoleId = 48;

//获得技能kind
global.gGetSkillKind = function(soldierKind, skillId) {
    var skill = +skillId;

    if (skill < 1000) {
        return soldierKind;
    } else if (skill < 2000) {
        return 'god';
    } else {
        return 'lord';
    }
};

// 是否是标准技能(非觉醒技能和化神技能)
global.gIsStandSkill = function(skillId) {
    return +skillId < 1000;
};

// 兵种类型
global.gSoldierKindMap = {
    'SWORD'   : 1,  //刀
    'SPEAR'   : 2,  //枪
    'RIDER'   : 3,  //骑
    'ADVISER' : 4,  //谋士
    'BEAUTY'  : 5,  //红颜
};

// 是否是魔法型(谋士/红颜)兵种
global.gIsMagicSoldierKind = function(kind) {
    return (gSoldierKindMap.ADVISER == kind) || (gSoldierKindMap.BEAUTY == kind);
};

// 武将属性名称映射
global.gRoleAttrNameMap = {
    Attack: 'attack',               //攻击
    Defence: 'defence',             //物防
    MDefence: 'mdefence',           //魔防
    MagicDefence: 'mdefence',       //魔防
    Health: 'health',               //士兵
    Miss: 'miss',                   //闪避
    Hit: 'hit',                     //命中
    Unblock: 'unblock',             //破招
    Block: 'block',                 //格挡
    Critdamage: 'critdamage',       //暴击
    Fortitude: 'fortitude',         //刚毅 
};

global.gRoleBasicAttrNameArr = ['attack', 'defence', 'mdefence', 'health', 'fortitude', 'hit', 'unblock', 'block', 'critdamage', 'miss'];


//邪将定义, {武将ID, 专属技能, 化神技能}
global.specRoleMap = {
    'LvBu'      : { 'id': 1,    'godSkill': 'addskillhurt',     'lordSkill': 'atkrowsplash' },
    'ZhaoYun'   : { 'id': 2,    'godSkill': 'atkrowsplash',     'lordSkill': 'addcritdamage' },
    'GuanYu'    : { 'id': 3,    'godSkill': 'addmiss',          'lordSkill': 'addnextatack' },
    'DianWei'   : { 'id': 12,   'godSkill': 'addmdefence',      'lordSkill': 'addskillhurt' },
    'ZhuGeliang': { 'id': 13,   'godSkill': 'addatkall',        'lordSkill': 'debaseatkall' },
    'DiaoChan'  : { 'id': 23,   'godSkill': 'reducehealth',     'lordSkill': 'debasehealth' },
    'ZuoCi'     : { 'id': 279,  'godSkill': 'addatkall',        'lordSkill': 'atkallstun' },
    'LuoShen'   : { 'id': 280,  'godSkill': 'addhealth',        'lordSkill': 'reducedamage' },
    'TongYuan'  : { 'id': 281,  'godSkill': 'addatkback',       'lordSkill': 'suckatkback' },
    'DongZuo'   : { 'id': 282,  'godSkill': 'reducehurt',       'lordSkill': 'addstrongatk' },
    'JiaXu'     : { 'id': 300,  'godSkill': 'reducemdefence',   'lordSkill': 'atkallsleep' },
    'HuaTuo'    : { 'id': 301,  'godSkill': 'addbaseatk',       'lordSkill': 'reducemdefence' },
    'XiangYu'   : { 'id': 302,  'godSkill': 'critaddmorale',    'lordSkill': 'atkrowascdamage' },
    'MaChao'    : { 'id': 303,  'godSkill': 'addatkreducemorale', 'lordSkill': 'addssrskillhurt' },
    'LiuLeLe'   : { 'id': 48,   'godSkill': 'atktransdefex',    'lordSkill': 'atkdecreasecol' },
};

global.gSpecRoleIndex = {};
for (var key in specRoleMap) {
    var id = specRoleMap[key].id;
    gSpecRoleIndex[id] = key;
}

global.gSpecActivitys = {
    thanksback: { alias:'thanks_back' },
    godgift: { world:true, worldArgs:[] },
    luckycharge: { world:true },
    imperialexamination: { world:true, worldArgs:['round'] },
}

global.gModExcept = {
    'activity': 2,
    'business': 3,
    'boss': 5,
    'leaguewar': 8,
}

global.GlobalSmashLandRank = {
    PERIOD_WAIT : 0,
    PERIOD_MATCH : 1,
    PERIOD_AWARD : 2,

    getRound : function() {
        var days = Math.ceil((Date.getStamp() - gConfRuntime.SmashLandRankFirstOpenTime)/86400);
        return Math.ceil(days/gConfGlobal.SmashLandRankPeriodDays);
    },

    getStep : function() {
        var days = Math.ceil((Date.getStamp() - gConfRuntime.SmashLandRankFirstOpenTime)/86400);
        days = (days-1)%gConfGlobal.SmashLandRankPeriodDays + 1;
        if (days <= gConfGlobal.SmashLandRankMatchDays) {
            return this.PERIOD_MATCH;
        } else if (days <= (gConfGlobal.SmashLandRankMatchDays + 1)) {
            return this.PERIOD_AWARD;
        } else {
           return this.PERIOD_WAIT; 
        }
    },

    getDays: function() {
        var days = Math.ceil((Date.getStamp() - gConfRuntime.SmashLandRankFirstOpenTime)/86400);
        return days%gConfGlobal.SmashLandRankPeriodDays;
    },
}

global.gGetSidFromUid = function(uid) {
    var sid = Math.floor(uid/1000000);
    if (uid > 100000000) {
       sid = Math.floor((uid-100000000)/100000); 
    }
    return sid - 1;
}
